﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.Permissions;

namespace Dwarf.Managed
{
    /// <summary>
    /// User interface for solving the Sparse Linear Algebra Problem.
    /// </summary>
    class Program
    {
        /// <summary>
        /// The settings for this dwarf.
        /// </summary>
        static private Settings settings;

        /// <summary>
        /// Get settings from the command line.
        /// </summary>
        /// <param name="args">
        /// Cli params.
        /// </param>
        /// <param name="slasolver">
        /// Instance of Solver.
        /// </param>
        static void getSettings(String[] args, Solver slasolver)
        {
            settings = new Settings();
            settings.Init(args, slasolver);
        }

        /// <summary>
        /// Point of the program start.
        /// </summary>
        /// <param name="args">
        /// Cli params.
        /// </param>
        static void Main(String[] args)
        {
            try
            {
                Solver slasolver = new Solver();

                getSettings(args, slasolver);   // Get settings from the command line.

                settings.Start();               // Start new time count.
                //This line of code is used for decrease of input file size.
                //Such modification would reduce the input file size, 
                //but the algorithm is still belongs dwarf.
                //Also this line does not affect the result.
                for (int k = 0; k < 200; k++)
                { slasolver.Solve(); }             // Solve the current problem.
                settings.Finish(slasolver);     // Stop the time count and write results.
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                usage();
            }

        }

        /// <summary>
        /// Write the rules of command line structure.
        /// </summary>
        [DllImport(@"CliTools.dll")]
        private static extern void usage();
    }
}
